package com.ponhu.ea2.stockcenter.provider.service.entity;

import com.baomidou.mybatisplus.extension.service.IService;
import com.ponhu.ea2.common.basic.util.time.DateUtils;
import com.ponhu.ea2.stockcenter.dto.OrderInfoDTO;
import com.ponhu.ea2.stockcenter.enums.DefinedSystem;
import com.ponhu.ea2.stockcenter.enums.ExchangeActionTypeEnum;
import com.ponhu.ea2.stockcenter.provider.entity.StockInventoryDocOccupy;
import com.ponhu.ea2.stockcenter.provider.support.enums.DocOccupyStatusEnum;
import com.ponhu.ea2.stockcenter.provider.support.enums.DocOccupyTransferStatusEnum;
import com.ponhu.ea2.stockcenter.provider.support.enums.StockChangeInnerEventEnum;

import java.util.List;

/**
 * 销售库存单据占用表服务类
 */
public interface StockInventoryDocOccupyService extends IService<StockInventoryDocOccupy> {

    default String getDocRecordRemark(Integer code, String msg) {
        return String.format("%s:%s==>%s || \n",
                code, msg,
                DateUtils.getCurrentDateTime());
    }

    default String getNewDocRecordRemark(Integer code, String msg, int status) {

        return String.format("%s:%s==>单据状态更新为:%s==>%s || \n",
                code, msg,
                DocOccupyStatusEnum.getName(status),
                DateUtils.getCurrentDateTime());
    }

    default String getNewDocRecordRemark(int transferStatus, Integer code, String msg) {

        return String.format("%s:%s==>调拨状态更新为:%s==>%s || \n",
                code, msg,
                DocOccupyTransferStatusEnum.getName(transferStatus),
                DateUtils.getCurrentDateTime());
    }

    default String getNewDocRecordRemark(Integer code, String msg, int status, boolean isUsed) {
        return String.format("%s:%s==>单据状态更新为:%s==>是否占用更新为:%s==>%s || \n",
                code, msg,
                DocOccupyStatusEnum.getName(status),
                isUsed, DateUtils.getCurrentDateTime());
    }

    default String getNewDocRecordRemark(Integer code, String msg, boolean isUsed, int transferStatus) {
        return String.format("%s:%s==>调拨状态更新为:%s==>是否占用更新为:%s==>%s || \n",
                code, msg,
                DocOccupyTransferStatusEnum.getName(transferStatus),
                isUsed, DateUtils.getCurrentDateTime());
    }

    /**
     * 获取"已下单"状态单据记录列表(已下单状态)
     *
     * @param inventoryCodeList 货品编码列表
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedDocRecordList(List<String> inventoryCodeList);

    /**
     * 获取"已下单"状态单据记录列表(已下单状态)
     * @param docNo
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedDocRecordList(String docNo);

    /**
     * 获取单据占用库存记录
     *
     * @param docNo 单据号
     * @return
     */
    List<StockInventoryDocOccupy> getDocRecordList(String docNo);

    /**
     * 获取单据占用库存记录
     *
     * @param docNo 单据号
     * @return
     */
    List<StockInventoryDocOccupy> getDocRecordList(String docNo, List<String> inventoryCodes);

    /**
     * 获取单据占用库存记录(已下单、已占用状态)
     *
     * @param docNo 单据号
     * @return
     */
    List<StockInventoryDocOccupy> getDocOccupyRecord(String docNo);

    /**
     * 获取已取消单据记录列表
     *
     * @param docNo 单据号
     * @return
     */
    List<StockInventoryDocOccupy> getCanceledDocRecordList(String docNo);

    /**
     * 获取单据占用库存记录(所有状态)
     *
     * @param docNo 单据号
     * @return
     */
    List<StockInventoryDocOccupy> getAllDocOccupyRecord(String docNo);

    /**
     * 获取单据占用库存记录(所有状态)
     *
     * @param inventoryCodeList 货品编码列表
     * @return
     */
    List<StockInventoryDocOccupy> getAllDocOccupyRecord(List<String> inventoryCodeList);

    /**
     * 取消单据占用销售层库存数(取消销售订单)
     *
     * @param docNo
     * @return
     */
    boolean cancelDocOccupy(String docNo, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 释放单据占用销售层库存数(调拨申请时同时调用销售层释放)
     *
     * @param docNo
     * @return
     */
    boolean releaseDocOccupy(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);


    /**
     * 获取"已下单"状态并且"未占用"的单据记录
     *
     * @param docNo
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedAndNoOccupyDocRecord(String docNo);

    /**
     * 获取"已下单"状态并且"已占用"且"未调拨申请并且未出可售仓"的单据记录
     *
     * @param docNo
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedAndOccupyAndNoTransferNoOutDocRecord(String docNo);

    /**
     * 将单据记录状态更新为"已出库"(针对已下单、未占用，销售出库)
     *
     * @param docNo
     * @return
     */
    boolean takeDocRecordOutOfWarehouseForNoUsed(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 将单据记录状态更新为"已出库"(针对已下单、已占用，销售出库直接出可售仓)
     *
     * @param docNo
     * @return
     */
    boolean takeDocRecordOutOfWarehouseForUsed(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 将单据更新为已出库
     * @param docNo
     * @param stockChangeInnerEventEnum
     * @return
     */
    boolean takeDocRecordSalesOut(String docNo, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 添加销售单占用库存记录
     *
     * @param orderInfoDTO
     */
    void addSalesOrderOccupyStockRecord(OrderInfoDTO orderInfoDTO, DefinedSystem definedSystem, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 将订单下的占用记录调拨状态更新为"未调拨申请并且未出可售仓"、"已占用"
     *
     * @param docNo
     * @return
     */
    boolean changeDocRecordToNoTransferAndNoOutAndUsed(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 将订单下的占用记录调拨状态更新为"未调拨申请并且未出可售仓"
     *
     * @param docNo
     * @return
     */
    boolean changeDocRecordToNoTransferAndNoOut(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 将订单下的占用记录调拨状态更新为"调拨已申请并且已出可售仓"
     *
     * @param docNo
     * @return
     */
    boolean changeDocRecordToTransferAppliedAndOuted(String docNo, ExchangeActionTypeEnum exchangeActionTypeEnum, StockChangeInnerEventEnum stockChangeInnerEventEnum);

    /**
     * 获取"已下单"状态并且"未占用"且"调拨已申请并且已出可售仓"的单据记录
     * @param docNo
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedAndNoOccupyAndTransferAppliedAndOutedDocRecord(String docNo);

    /**
     * 获取"已下单"状态并且"未占用"且"调拨已申请并且未出可售仓"的单据记录
     * @param docNo
     * @return
     */
    List<StockInventoryDocOccupy> getPlacedAndNoOccupyAndTransferAppliedAndNoOutedDocRecord(String docNo);


}
